﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QuanLyNhaThuoc.Models;

namespace QuanLyNhaThuoc.Controllers
{
    public class HomeController : Controller
    {
        PMOEntities PMOEn = new PMOEntities();

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            #region Check session login
            if (HttpContext.Session["USERID"] == null)
            {
                Response.Redirect("~/Account/LogIn");
            }
            #endregion

            #region Check function permission
            string controller = RouteData.Values["controller"].ToString();
            string action = RouteData.Values["action"].ToString();

            var query = PMOEn.CheckFunctionPermission(Session["USERID"].ToString(), controller, action).ToList();
            if (query.Count != 0)
            {
                ViewBag.Title = query[0].Title;
            }
            else
            {
                Response.Redirect("~/Error/Denied");

            }
            #endregion

            base.OnActionExecuting(filterContext);
        }
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

    }
}
